public class text7 {
    public static int fun7(int[] array){
        int tmp=array[0];
        int count=0;
        for(int i=0;i< array.length;i++){
            if(array[i]==tmp){
                count++;
            } else if (array[i]!=count) {
                count--;
                }
            if(count==0){
                tmp=array[i];
                count++;
            }
        }
        return tmp;
    }

    public static void main(String[] args) {
        int[] array={1,3,2,5,5,5,5,6,6};
        int x=fun7(array);
        System.out.println(x);
    }
}
